import 'package:flutter/material.dart';
import 'package:flutter_section_table_view/flutter_section_table_view.dart';
import 'package:ls_work/a_yyt/models/pending_selected_group_entity.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/styles.dart';

class PendingSelectedStaffPage extends StatefulWidget {
  List<PendingSelectedGroupEntity> orginList = [];
  PendingSelectedStaffPage({Key? key,required this.orginList});
  @override
  _PendingSelecteStaffPageState createState() =>
      _PendingSelecteStaffPageState();
}

class _PendingSelecteStaffPageState extends State<PendingSelectedStaffPage> {
  @override
  Widget build(BuildContext context) {
    print('子界面2  - ${widget.orginList.length}');
    return SectionTableView(
      sectionCount: widget.orginList.length,
      numOfRowInSection: (section) {
        return (widget.orginList[section].user??[]).length;
      },
      cellAtIndexPath: (section, row) {
        return Container(
          height: 60.0,
          padding: EdgeInsets.only(left: 30, right: 30),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Text(
                ' ${widget.orginList[section].user![row].userName}',
                style: TextStyles.textDark18,
              ),
              Checkbox(
                value: widget.orginList[section].user![row].isSelected != null ? widget.orginList[section].user![row].isSelected : false,
                onChanged: (value) {
                  setState(() {
                    widget.orginList[section].user![row].isSelected = value;
                    if (value==true) {
                      for (PendingSelectedGroupEntity info
                          in widget.orginList) {
                        for (var item in (info.user??<PendingSelectedGroupInfo>[])) {
                          if (item.userId !=
                              widget.orginList[section].user![row].userId) {
                            item.isSelected = false;
                          }
                        }
                      }
                    }
                  });
                },
              )
            ],
          ),
        );
      },
      headerInSection: (section) {
        return Container(
          height: 64.0,
          padding: EdgeInsets.only(left: 30),
          color: Colours.bg_color,
          alignment: Alignment.centerLeft,
          child: Text(
            ' ${widget.orginList[section].serviceTypeName}',
            style: TextStyles.textDark20,
          ),
        );
      },
      divider: Container(
        color: Colours.line,
        height: 1.0,
      ),
    );
  }
}
